#include "itemwidget.h"
#include <QApplication>
#include <QPixmap>
#include <QLabel>
#include <QFont>
#include <QPoint>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QDebug>
#include <QCursor>
#include <QFontMetrics>


ItemWidget::ItemWidget(ObjectInfo param, QWidget *parent)
    :QWidget(parent)
    ,m_param(param)
{
    //LOG_QDEBUG<<"ItemWidget::ItemWidget"<<param.width<<param.height;
    setWindowFlags(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);
    setObjectName(m_param.object_name);

    lab_name = new QLabel(m_param.object_name, this);
    lab_name->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);

    QHBoxLayout *layout = new QHBoxLayout;

    layout->addWidget(lab_name);
    setLayout(layout);
}

ItemWidget::~ItemWidget()
{

}

void ItemWidget::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton)
    {
         QCursor cursor;
         cursor.setShape(Qt::SizeAllCursor);
         QApplication::setOverrideCursor(cursor);
    }
    QWidget::mousePressEvent(event);
}

void ItemWidget::mouseReleaseEvent(QMouseEvent *event)
{
     QApplication::restoreOverrideCursor();

    if (event->button() == Qt::LeftButton)
    {
        emit mouseRelease(get_param(), event->globalPos());
    }
    QWidget::mouseReleaseEvent(event);
}

void ItemWidget::mouseDoubleClickEvent(QMouseEvent *event)
{
    emit mouseDoubleClick(objectName());
    QWidget::mouseDoubleClickEvent(event);
}

ObjectInfo ItemWidget::get_param()
{
    return m_param;
}

